package com.stevens.triangles;

import java.util.Arrays;
import java.util.Scanner;

public class JamieTriangles extends TrianglesBase
{
	public JamieTriangles(double[] triangleSides)
	{
		super(triangleSides);
	}

	@Override
	public String kindOfTriangle()
	{
		// STEP 0: Make sure input is valid.
		if(this.triangleSides.length < 3)
			return kTooFewSidesError;
		if(this.triangleSides.length > 3)
			return kTooManySidesError;
		
		// STEP 1: Determine number of equal sides
		int eqSides = 0;
		
		// For three sides A, B, C
		// AB
		if (this.triangleSides[0] == this.triangleSides[1])
			eqSides++;
		// AC
		if (this.triangleSides[0] == this.triangleSides[2])
			eqSides++;
		// BC
		if (this.triangleSides[1] == this.triangleSides[2])
			eqSides++;
		
		String answer; // output message
		
		// STEP 2: Determine type.
		switch (eqSides) 
		{
			case 0:
				answer = "Scalene";
				break;
			case 1:
				answer = "Isosceles";
				break;
			case 3:
				answer = "Equilateral";
				break;
			default:
				answer = "";
		}
		
		// Sort arrays in order
		Arrays.sort(this.triangleSides);
		
		// STEP 3: Perform Pythagorean Theorem, determine if triangle is "Right"
		if(Math.abs(Math.pow(this.triangleSides[0], 2)+ Math.pow(this.triangleSides[1], 2) - Math.pow(this.triangleSides[2], 2)) < 0.01) 
		{ 
				answer = answer.concat(" Right Triangle");
		} 
		else answer = answer.concat(" Triangle");
		return answer;
	}
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		double[] data = new double[3];
		for(int i = 0; i < 3; i++) 
		{
			System.out.print("Enter side "+(i+1)+" : ");
			data[i] = in.nextDouble();
		}	
		JamieTriangles tri = new JamieTriangles(data);
		System.out.println(tri.kindOfTriangle()+"\n\nCompleted.");
	}
}